import java.util.ArrayList;
import java.util.Scanner;
public class Main{
public static void main (String[] args){
    ArrayList<Student> student =new ArrayList<Student>();
    while(true){
    
    
    System.out.println("——————————学生管理系统——————————");
    System.out.println("输入1添加学生");
    System.out.println("输入2删除学生");
    System.out.println("输入3修改学生");
    System.out.println("输入4查看学生");
    System.out.println("输入5退出系统");
    System.out.println("请输入数字以执行功能");
    Scanner n = new Scanner(System.in);
    int a=n.nextInt();
    
    switch(a){
        case 1:
        System.out.println("添加学生");
        adds(student);
        break;
        case 2:
        System.out.println("删除学生");
        dela(student);
        break;
        case 3:
        System.out.println("修改学生");
        fix(student);
        break;
        case 4:
        System.out.println("查看学生");
        shows(student);
        break;
        case 5:
        System.out.println("退出系统");
        //JVM退出
        System.exit(0);
        
        
    }
}
}

public static void adds(ArrayList<Student>arr){
Scanner stu = new Scanner(System.in);

System.out.println("请输入姓名");
String name = stu.nextLine();

System.out.println("请输入年龄");
String age = stu.nextLine();

System.out.println("请输入学号");
String ids = stu.nextLine();

System.out.println("请输入祖籍");
String place = stu.nextLine(); 

Student x = new Student();
x.setName(name);
x.setAge(age);
x.setIds(ids);
x.setPlace(place);

arr.add(x);



System.out.println("录入成功");
}


public static void shows (ArrayList<Student>arr){
    if(arr.size()==0){
    System.out.println("无信息");
    }else{
    System.out.println("姓名   年龄  学号      祖籍  ");
    for(int i=0;i<arr.size();i++){
    Student v = arr.get(i);
    System.out.println(v.getName()+"--"+v.getAge()+"--"+v.getIds()+"--"+v.getPlace());
    }
}
}

public static void dela(ArrayList<Student>arr){
    Scanner e = new Scanner(System.in);
    System.out.println("请输入要删除学生的学号");
    String f=e.nextLine();
    for(int i=0;i<arr.size();i++){
    if(arr.get(i).getIds().equals(f)){
        arr.remove(i);
        System.out.println("删除成功");
        break;
        }else{
        System.out.println("删除失败");
        }
    }
    
}


public static void fix(ArrayList<Student>arr){
    Scanner e = new Scanner(System.in);
    System.out.println("请输入要修改学生的学号");
    String f=e.nextLine();
    
    System.out.println("请输入姓名");
    String name = e.nextLine();

    System.out.println("请输入年龄");
    String age = e.nextLine();

    System.out.println("请输入学号");
    String ids = e.nextLine();

    System.out.println("请输入祖籍");
    String place = e.nextLine();
    
    Student s=new Student(name,age,ids,place);
    
    for(int i=0;i<arr.size();i++){
    if(arr.get(i).getIds().equals(f)){
        arr.set(i,s);
        System.out.println("修改成功");
        break;
        }else{
            System.out.println("修改失败");
        }
    }
    
}


}